package com.neo.category.mapper;

import java.util.List;

import com.neo.common.domain.Category;
import org.apache.ibatis.annotations.*;

/**
 * @Author: chenb
 * @CreateTime: 2024/3/20 13:33
 * @Description:
 */
@Mapper
public interface CategoryMapper {

  //推荐使用#{}取值，不要用${},因为存在注入的风险
  @Insert("INSERT INTO tb_category(category_name,ext1,ext2,ext3,create_time,is_del) VALUES(#{category_name},#{ext1},#{ext2},#{ext3},  #{create_time},#{is_del})")
  @Options(useGeneratedKeys=true, keyProperty="id", keyColumn="id")   //keyProperty java对象的属性；keyColumn表示数据库的字段
  int insert(Category category);

  //column指数据库中的列，property是指实体的属性名，如果一致就不需要写
  @Select("SELECT * FROM tb_category")
  @Results({
//      @Result(column = "create_time",property = "createTime")
  })
  List<Category> getAll();

  @Select("SELECT * FROM tb_category WHERE id = #{id} and is_del = '0' ")
  Category findById(Long id);

  @Update("UPDATE tb_category SET category_name=#{category_name} WHERE id =#{id}")
  void update(Category category);

  @Delete("DELETE FROM tb_category WHERE id =#{id}")
  void delete(Long categoryId);
}
